package com.jw.system.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jw.response.Result;
import com.jw.system.entity.User;
import com.jw.system.entity.vo.PageVO;
import com.jw.system.entity.vo.UserVO;
import com.jw.system.service.RoleService;
import com.jw.system.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 用户表 前端控制器
 * </p>
 *
 * @author jw
 * @since 2021-04-20
 */
@RestController
@RequestMapping("/user")
@Api(value = "系统用户模块", tags = "系统用户接口")
public class UserController {

    @Autowired
    private UserService userService;


    /**
     * 获取用户列表
     * @return
     */
    @ApiOperation(value = "用户列表", notes = "模糊查询用户列表")
    @PostMapping("/getUserList")
    public Result getUserList(@RequestParam(value = "current", defaultValue = "1") Integer current,
                              @RequestParam(value = "size", defaultValue = "7") Integer size,
                              @RequestBody UserVO userVO){
        Page<UserVO> userList = userService.getUserList(current, size, userVO);
        return Result.ok().data("userList",userList.getRecords()).data("total",userList.getTotal());
    }

    @ApiOperation(value = "用户信息", notes = "用户登入信息")
    @GetMapping("/getUserInfo")
    public Result info() {
        UserVO user = userService.getUserInfo();
        return Result.ok().data("Info",user);
    }

    /**
     * 添加用户
     */
    @ApiOperation(value = "添加用户", notes = "添加用户")
    @PostMapping("/add")
    public Result add(@RequestBody User user){
        userService.addUser(user);
        return Result.ok();
    }

    @ApiOperation(value = "出入库审核人", notes = "获取仓储主管列表")
    @GetMapping("/getAuditorList")
    public Result getAuditorList(@RequestParam(value = "id", required = false) Long id){
        List<User> auditorsList = userService.getAuditorsList(id);
        return Result.ok().data("auditorsList",auditorsList);
    }


}

